﻿namespace Vestras.StarCraft2.Luna.Parser.Ast {
    public abstract class Entity {
        Entity parent;

        public string FileName { get; set; }
        public int StartLine { get; protected internal set; }
        public int StartColumn { get; protected internal set; }
        public int EndLine { get; protected internal set; }
        public int EndColumn { get; protected internal set; }
        public virtual Entity Parent {
            get {
                return parent;
            }
            internal set {
                if (parent != null) {
                    if (parent is EntityWithBlock) {
                        EntityWithBlock block = (parent as EntityWithBlock);
                        if (block != null && block.Children.Contains(this)) {
                            block.Children.Remove(this);
                        }
                    }
                }

                parent = value;
                if (parent != null) {
                    if (parent is EntityWithBlock) {
                        EntityWithBlock block = (parent as EntityWithBlock);
                        if (block != null && !block.Children.Contains(this)) {
                            block.Children.Add(this);
                        }
                    }
                }
            }
        }


        protected Entity() { }
    }
}
